package com.goods.controller.business;

import com.github.pagehelper.PageInfo;
import com.goods.business.service.ConsumerService;
import com.goods.common.model.business.Consumer;
import com.goods.common.model.business.Supplier;
import com.goods.common.response.ResponseBean;
import com.goods.common.vo.business.ConsumerVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import java.util.HashMap;
import java.util.Map;

/**
 * @author ：Hachimen
 * @date ：Created in 2021/9/27 9:57
 * @description：物资去处
 * @modified By：
 * @version:
 */
@RestController
public class ConsumerWebController {
    @Autowired
    private ConsumerService consumerService;

    //物资去处 分页查询
    //http://www.localhost:8989/business/consumer/findConsumerList?pageNum=1&pageSize=10&name=333&address=111&contact=222
    @GetMapping("/business/consumer/findConsumerList")
    public ResponseBean findConsumerList(ConsumerVO consumerVO,HttpServletRequest request){
        String pageNum = request.getParameter("pageNum");
        String pageSize = request.getParameter("pageSize");

        PageInfo<ConsumerVO> page = consumerService.findConsumerList(pageNum,pageSize,consumerVO);
        Map<String, Object> data = new HashMap<>();
        data.put("total",page.getTotal());
        data.put("rows",page.getList());
        return ResponseBean.success(data);
    }

    //物资去处 添加
    @PostMapping("/consumer/add")
    public ResponseBean add(@RequestBody ConsumerVO consumerVO){
        consumerService.add(consumerVO);
        return ResponseBean.success();
    }

    //物资去处 编辑之 查单个
    @GetMapping("business/consumer/edit/{id}")
    public ResponseBean edit(@PathVariable Long id){
        ConsumerVO consumerVO = consumerService.edit(id);
        return ResponseBean.success(consumerVO);
    }

    //物资去处 编辑之 改单个
    @PutMapping("business/consumer/update/{id}")
    public ResponseBean update(@RequestBody ConsumerVO consumerVO){
        consumerService.update(consumerVO);
        return ResponseBean.success();
    }

    //物资去处 删除
    @DeleteMapping("business/consumer/delete/{id}")
    public ResponseBean update(@PathVariable Long id){
        consumerService.delete(id);
        return ResponseBean.success();
    }

    //物资去处 物资出库 查全部
    @GetMapping("/business/consumer/findAll")
    public ResponseBean findAll(){
        PageInfo<ConsumerVO> page = consumerService.findConsumerList(null,null,null);
        return ResponseBean.success(page.getList());
    }
}
